package com.example.permissionsystem1_1.common.businessFunction;

import com.example.permissionsystem1_1.common.entity.BasePo;
import com.example.permissionsystem1_1.common.entity.baseReqModel.BaseInsertReqModel;
import com.example.permissionsystem1_1.common.entity.baseReqModel.BaseUpdateBatchByIdsReqModel;
import com.example.permissionsystem1_1.common.entity.baseReqModel.BaseUpdateByIdReqModel;

import java.util.Date;
import java.util.List;

public class BaseServiceConverter {
    public static BaseInsertReqModel setDefaultAttributesValue(BaseInsertReqModel reqModel){
//        if(reqModel==null){//到此步时,reqModel一定不为null
//            reqModel=new BaseInsertReqModel();
//        }
        if(reqModel.getState()==null){
            reqModel.setState("0");
        }
        if(reqModel.getCreator()==null){
            reqModel.setCreator("admin");
        }
        if(reqModel.getUpdator()==null){
            reqModel.setUpdator("admin");
        }
        Date now=new Date();
        if(reqModel.getCreateTime()==null){
            reqModel.setCreateTime(now);
        }
        if(reqModel.getUpdateTime()==null){
            reqModel.setUpdateTime(now);
        }
        return reqModel;
    }

    public static BaseUpdateByIdReqModel setDefaultAttributesValue(BaseUpdateByIdReqModel reqModel){
//        if(reqModel==null){//到此步时,reqModel一定不为null
//            reqModel=new BaseInsertReqModel();
//        }
        if(reqModel.getUpdator()==null){
            reqModel.setUpdator("admin");
        }
        Date now=new Date();
        if(reqModel.getUpdateTime()==null){
            reqModel.setUpdateTime(now);
        }
        return reqModel;
    }

    public static BaseUpdateBatchByIdsReqModel setDefaultAttributesValue(BaseUpdateBatchByIdsReqModel reqModel){
//        if(reqModel==null){//到此步时,reqModel一定不为null
//            reqModel=new BaseInsertReqModel();
//        }
        if(reqModel.getUpdator()==null){
            reqModel.setUpdator("admin");
        }
        Date now=new Date();
        if(reqModel.getUpdateTime()==null){
            reqModel.setUpdateTime(now);
        }
        return reqModel;
    }

    public static BasePo setDefaultAttributesValue(BasePo po){
//        if(reqModel==null){//到此步时,reqModel一定不为null
//            reqModel=new BaseInsertReqModel();
//        }
        if(po.getState()==null){
            po.setState("0");
        }
        if(po.getCreator()==null){
            po.setCreator("admin");
        }
        if(po.getUpdator()==null){
            po.setUpdator("admin");
        }
        Date now=new Date();
        if(po.getCreateTime()==null){
            po.setCreateTime(now);
        }
        if(po.getUpdateTime()==null){
            po.setUpdateTime(now);
        }
        return po;
    }

//    public static List<BasePo> setDefaultAttributesValue(List<BasePo> pos){
//        Date now=new Date();
//        String defaultCreator="admin";
//        String defaultUpdator="admin";
//        String defaultState="0";
//        for (BasePo po:pos) {
//            //        if(reqModel==null){//到此步时,reqModel一定不为null
////            reqModel=new BaseInsertReqModel();
////        }
//            if(po.getState()==null){
//                po.setState(defaultState);
//            }
//            if(po.getCreator()==null){
//                po.setCreator(defaultCreator);
//            }
//            if(po.getUpdator()==null){
//                po.setUpdator(defaultUpdator);
//            }
//            if(po.getCreateTime()==null){
//                po.setCreateTime(now);
//            }
//            if(po.getUpdateTime()==null){
//                po.setUpdateTime(now);
//            }
//        }
//        return pos;
//    }


}
